package com.neouton.crm.enterprise.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neouton.common.util.PageUtil;
import com.neouton.common.util.ResponseAPI;
import com.neouton.crm.enterprise.entity.EnterpriseVO;
import com.neouton.crm.enterprise.service.IEnterpriseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: crm
 * @Timestamp: 2022-11-1
 * @Author: LiBingKun
 * @Description: 工商信息相关接口
 */
@RestController
@RequestMapping("enterprise")
public class EnterpriseController {

    @Resource
    private IEnterpriseService enterpriseService;

    /**
     * 多条件分页查询企业信息列表
     * @Timestamp: 2022-11-1
     * @Author: LiBingKun
     * @param pageNum 当前页
     * @param pageSize 每页数量
     * @param enterprise 其余查询条件
     * @return 分页查询结果
     */
    @PostMapping("/getEnterprisesByPage/{pageNum}/{pageSize}")
    public ResponseAPI getEnterprisesByPage(@PathVariable(value = "pageNum") int pageNum,
                            @PathVariable(value = "pageSize") int pageSize,
                            @RequestBody EnterpriseVO enterprise) {
        IPage<EnterpriseVO> page = new Page<>(pageNum, pageSize, true);
        PageUtil<EnterpriseVO> result = enterpriseService.queryEnterpriseByPage(page, enterprise);
        return ResponseAPI.successData(result);
    }

    /**
     * 获取所有工商信息接口，对外提供
     * @param source
     * @return
     */
    @PostMapping("/getEnterprises/{source}")
    public ResponseAPI queryEnterprises(@PathVariable(value = "source") String source) {
        List<EnterpriseVO> result = enterpriseService.queryEnterprises(source);
        return ResponseAPI.successData(result);
    }


    /**
     * 保存或更新工商信息
     * @Timestamp: 2022-11-3
     * @Author: LiBingKun
     * @param enterprise 需更新实体
     * @return 成功失败
     */
    @PostMapping("/saveOrUpdateEnterprises")
    public ResponseAPI saveOrUpdateEnterprises(@RequestBody EnterpriseVO enterprise) {
        Integer enterpriseId = enterpriseService.saveOrUpdateEnterprises(enterprise);
        return ResponseAPI.successData(enterpriseId);
    }

    /**
     * 删除工商信息
     * @Timestamp: 2022-11-3
     * @Author: LiBingKun
     * @param enterprisesId 需删除的ID
     * @return 成功失败
     */
    @PostMapping("/deleteEnterprises/{enterprisesId}/{backUserId}")
    public ResponseAPI deleteEnterprises(@PathVariable(value = "enterprisesId") Integer enterprisesId,
                                         @PathVariable(value = "backUserId") Integer backUserId){
        Boolean falge = enterpriseService.deleteEnterprisesById(enterprisesId,backUserId);
        return ResponseAPI.successData(falge);
    }

    /**
     * 更具部分条件查询工商信息是否存在
     * @Timestamp: 2022-11-3
     * @Author: LiBingKun
     * @param enterprise 条件封装实体类
     * @return true存在，false不存在
     */
    @PostMapping("/queryEnterpriseExit")
    public ResponseAPI queryEnterpriseExit(@RequestBody EnterpriseVO enterprise){
        Boolean falge = enterpriseService.queryEnterpriseExit(enterprise);
        return ResponseAPI.successData(falge);
    }


}
